<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="/system/common/libs/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="/system/common/libs/bootstrap/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/system/common/custom/css/common.css">
    <link rel="stylesheet" type="text/css" href="/frame/css/primary.css" class="css-href"/>
    <script language="JavaScript" src="/system/common/libs/js/jquery.min.js"></script>
    <script language="JavaScript" src="/system/common/libs/bootstrap/js/bootstrap.min.js"></script>
    <script language="JavaScript" src="/system/common/libs/laydate/laydate.js"></script>
    <script language="JavaScript" src="/system/common/custom/js/common.js"></script>
    <style>
        .error-info {
            display: none;
            color: #a94442;
        }
        table tr td{
            height: 32px;
            width: 360px;
        }
       #setPwd table tr td input{
            height: 32px!important;
            width: 360px;
           margin-bottom: 20px!important;
        }
        .btn-submit{
            height: 32px!important;
            width: 80px!important;
            line-height: 32px;
            margin-left: 0!important;
        }
        .myContainer{
            margin: 0;
        }
    </style>
</head>
<body>
<div class="container myContainer">
    <form id="setPwd" style="margin-top: 15px">
        <table>
            <tr>
                <td><input type="password" class="form-control" name="oldpwd" required="required" placeholder="请输入原密码"></td>
            </tr>
            <tr>

                <td><input type="password" class="form-control" name="pwd" required="required" placeholder="请输入新密码"></td>
            </tr>
            <tr>

                <td><input type="password" class="form-control" name="repwd" required="required" placeholder="请再次输入新密码"></td>
            </tr>
        </table>
        <input type="button" class="btn-submit btn-primary" value="提交">
    </form>
</div>
<script>
    $(function() {
        $('form[id="setPwd"] input').on('keyup', function() {
            var oldpwd= $('input[name=oldpwd]').val();
            var pwd= $('input[name=pwd]').val();
            var repwd= $('input[name=repwd]').val();
            if(!oldpwd){
                $.x_alertMsg('请输入原密码！');
                return false;
            }

            if(!pwd){
                $.x_alertMsg('请输入新密码！');
                return false;
            }

            if(!repwd){
                $.x_alertMsg('请再次输入新密码！');
                return false;
            }
            if(!$(this).val()) {
                $(this).addClass('xinput-error');
                $.x_alertMsg('请输入密码！', 0, 5000);
            }else if($(this).attr('name') == 'repwd') {
                if($(this).val() != $('input[name=pwd]').val()) {
                    $(this).addClass('xinput-error');
                    $.x_alertMsg('两次输入的密码不一样！');
                } else {
                    $('form[id="setPwd"] input').removeClass('xinput-error');
                }
            }else if($(this).attr('name') == 'pwd'){
                if($(this).val() != $('input[name=repwd]').val()) {
                    $(this).addClass('xinput-error');
                    $.x_alertMsg('两次输入的密码不一样！');
                } else {
                    $('form[id="setPwd"] input').removeClass('xinput-error');
                }
            }
        });

        $('form[id="setPwd"] .btn-submit').on('click', function() {
            if ($('.xinput-error').length > 0) {
                $.x_alertMsg("请完善数据!");
            } else {
                var oldpwd = $("input[name=oldpwd]").val();
                var pwd = $("input[name=pwd]").val();
                var repwd = $("input[name=repwd]").val();

                if (oldpwd && pwd && repwd) {
                    jQuery.ajax({
                        url: "/system/user/setPwd.do",
                        type: "post",
                        data: {oldpwd: oldpwd, newpwd: pwd},
                        success: function (data) {
                            if (data && data.status == "1") {
                                $.x_alertMsg("保存成功!");
                            } else {
                                $.x_alertMsg(data['message']);
                            }
                        }
                    });
                } else {
                    $.x_alertMsg("请完善数据!");
                }
            }
        });
    });
</script>
</body>
</html>